package com.lemonPiggy.UDForm.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.lemonPiggy.UDForm.domain.UDFormApplication;
import com.lemonPiggy.UDForm.domain.UDFormWebPage;
import com.lemonPiggy.UDForm.mapper.UDFormApplicationMapper;
import com.lemonPiggy.UDForm.mapper.UDFormWebPageMapper;
import com.ruoyi.common.core.utils.IdUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lemonPiggy.UDForm.service.IUDFormApplicationService;

/**
 * 应用Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-02
 */
@Service
public class UDFormApplicationServiceImpl implements IUDFormApplicationService
{
    @Autowired
    private UDFormApplicationMapper UDFormApplicationMapper;
    @Autowired
    private UDFormWebPageMapper UDFormWebPageMapper;
    /**
     * 查询应用
     * 
     * @param id 应用ID
     * @return 应用
     */
    @Override
    public UDFormApplication selectUDFormApplicationById(String id)
    {
        return UDFormApplicationMapper.selectUDFormApplicationById(id);
    }

    /**
     * 查询应用列表
     * 
     * @param UDFormApplication 应用
     * @return 应用
     */
    @Override
    public List<UDFormApplication> selectUDFormApplicationList(UDFormApplication UDFormApplication)
    {
        return UDFormApplicationMapper.selectUDFormApplicationList(UDFormApplication);
    }

    /**
     * 新增应用
     * 
     * @param UDFormApplication 应用
     * @return 结果
     */
    @Override
    public int insertUDFormApplication(UDFormApplication UDFormApplication)
    {
        String uuid = IdUtils.simpleUUID();
        UDFormApplication.setId(uuid);
        UDFormApplication.setCreatedBy(SecurityUtils.getUsername());
        UDFormApplication.setUpdatedBy(SecurityUtils.getUsername());
        UDFormApplication.setCreatedTime(new Date());
        UDFormApplication.setUpdatedTime(new Date());
        return UDFormApplicationMapper.insertUDFormApplication(UDFormApplication);
    }

    /**
     * 修改应用
     * 
     * @param UDFormApplication 应用
     * @return 结果
     */
    @Override
    public int updateUDFormApplication(UDFormApplication UDFormApplication)
    {
        return UDFormApplicationMapper.updateUDFormApplication(UDFormApplication);
    }

    /**
     * 批量删除应用
     * 
     * @param ids 需要删除的应用ID
     * @return 结果
     */
    @Override
    public int deleteUDFormApplicationByIds(String[] ids) {
        for (String id : ids) {
            List<UDFormWebPage> list = UDFormWebPageMapper.selectApplication(id);
            System.out.println(list+"-------------");
            if (list.size()>0) {
                return -1;
            }
        }
        return UDFormApplicationMapper.deleteUDFormApplicationByIds(ids);
    }
    /**
     * 删除应用信息
     * 
     * @param id 应用ID
     * @return 结果
     */
    @Override
    public int deleteUDFormApplicationById(String id)
    {
        return UDFormApplicationMapper.deleteUDFormApplicationById(id);
    }

    @Override
    public List<Map<String, Object>> optionselect(UDFormApplication UDFormApplication) {
        return UDFormApplicationMapper.optionselect(UDFormApplication);
    }

}
